package com.bw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import  com.bw.entity.Area;
import  com.bw.mapper.AreaMapper;
import  com.bw.service.IAreaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 飓风微尘
 * @since 2022-05-02
 */
@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements IAreaService {
    @Autowired
    AreaMapper areaMapper;
    @Override
    public List<Area> listtree() {
        QueryWrapper<Area> wrapper = new QueryWrapper<>();
        wrapper.eq("pid",1);
        List<Area> list = this.list(wrapper);
        list.forEach(p->{
            QueryWrapper<Area> pwrapper = new QueryWrapper<>();
            pwrapper.eq("pid",p.getId());
            List<Area> listCity = this.list(pwrapper);
            p.setChildren(listCity);


            listCity.forEach(c->{
                QueryWrapper<Area> cwrapper = new QueryWrapper<>();
                cwrapper.eq("pid",c.getId());
                List<Area> listDistrict= this.list(cwrapper);
                c.setChildren(listDistrict);
            });
        });
        return list;
    }
}
